package com.bangcommunity.bbframe.mq.kafka.serial;

import com.bangcommunity.bbframe.mq.IQtMessager;
import com.bangcommunity.bbframe.serial.kryo.KryoObjectInput;
import org.apache.kafka.common.serialization.Deserializer;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Map;

/**
 * Created by tanghc on 17/2/4.
 */
public class QtMessageDeserializer implements Deserializer<IQtMessager> {
    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {

    }

    @Override
    public IQtMessager deserialize(String topic, byte[] data) {
        ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
        KryoObjectInput input = new KryoObjectInput(inputStream);
        try {
            return input.readObject(IQtMessager.class);
        } catch (IOException e) {
            throw new RuntimeException("deserilize qtmessager ioexception", e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("serilize qtmessager classnotfound exception", e);
        }
    }

    @Override
    public void close() {

    }
}
